Hello all,
I'm using the Object History script by Galactic Solutions, and am noticing that the memory used is never cleared after closing the DOORS module, or the dialog box the script uses to display object history. It seems that they are deleting the buffers used, but I can't figure out what else is holding all this data in memory. Could it be skip lists? I've looked through this forum on skip list deleting, and have tried some test runs on my own, but I am not familiar enough with DXL to figure this out. From what I can tell it caches the entire module in memory so that the history can be pulled up quickly, but this should be deallocated after the dialog box is closed. Ideally I'd like to only have the script grab the history for the current object selected, instead of the entire module.
Any advice? Thank you!
Their script is found here: http://galactic-solutions.com/downloads/History_112.zip
adam.clouthier - Wed Sep 25 15:01:21 EDT 2019 |
Re: Object History not freeing Memory
// Show all history records for an object (including baselines)
pragma runLim,0
const string HB_MAIN_TITLE = "History including Baselines"
const string HB_VERSION = "1.1.2"
const string HB_TITLE = HB_MAIN_TITLE " (v" HB_VERSION ") "
const string HB_TAB_LABELS[] = { "General", "About" }
const int HB_GENERAL_TAB = 0
const int HB_ABOUT_TAB = 1
const int HB_TAB_WIDTH = 800
const int HB_TAB_HEIGHT = 525
const int HB_DB_OFFSET = 60
const int HB_DB_WIDTH = HB_TAB_WIDTH
const int HB_DB_HEIGHT = HB_TAB_HEIGHT + HB_DB_OFFSET
const int HB_COLUMN_USER = 0
const int HB_COLUMN_SESSION = 1
const int HB_COLUMN_DATE = 2
const int HB_COLUMN_MODIFICATION = 3
const int HB_COLUMN_BASELINE = 4
const int HB_COLUMN_USER_WIDTH = 100
const int HB_COLUMN_SESSION_WIDTH = 50
const int HB_COLUMN_DATE_WIDTH = 120
const int HB_COLUMN_MODIFICATION_WIDTH = 260
const int HB_COLUMN_BASELINE_WIDTH = 180
const string HB_COLUMN_USER_LABEL = "User"
const string HB_COLUMN_SESSION_LABEL = "Session"
const string HB_COLUMN_DATE_LABEL = "Date"
const string HB_COLUMN_MODIFICATION_LABEL = "Modification"
const string HB_COLUMN_BASELINE_LABEL = "Baseline"
const int HB_historyListViewDBE_options = 0
const int HB_historyListViewDBE_width = 0
const int HB_historyListViewDBE_lines = 10
const int HB_oldAttrValueDBE_width = 500
const int HB_oldAttrValueDBE_height = 100
const int HB_newAttrValueDBE_width = 500
const int HB_newAttrValueDBE_height = 100
const string HB_oldAttrValueDBE_label = "From:"
const string HB_newAttrValueDBE_label = "To:"
const string HB_warnNullModule = "Please run in an open Module"
const string HB_warnNullObject = "No Object is selected."
const string HB_warnBaseline = "Please run from the current version of the Module"
const string HB_viewChangesAsRedliningDBE_label = "View changes as redlining"
DB HB_DB = null
DBE HB_TabDBE = null
DBE HB_historyListViewDBE = null
DBE HB_oldAttrValueDBE = null
DBE HB_newAttrValueDBE = null
DBE HB_viewChangesAsRedliningDBE = null
DBE HB_aboutTextDBE = null
Skip HB_TabSkip = null
Skip HB_GeneralTabSkip = null
Skip HB_AboutTabSkip = null
Skip HB_oldAttrValues = null
Skip HB_newAttrValues = null
Trigger HB_Trigger
Buffer HB_stripRichText( string rts ) {
Buffer plainText = create
RichText rt
for rt in rts do {
plainText += rt.text
if ( rt.newline ) plainText += "\n"
}
return plainText
}
void HB_onListViewSelect( DBE x, int i ) {
string newAttrStrValue = ""
if ( find( HB_newAttrValues, i, newAttrStrValue ) ) {
set( HB_newAttrValueDBE, newAttrStrValue )
}
else {
set( HB_newAttrValueDBE, " " )
}
string oldAttrStrValue = ""
if ( find( HB_oldAttrValues, i, oldAttrStrValue ) ) {
if ( get( HB_viewChangesAsRedliningDBE ) ) {
useRTFColour( HB_oldAttrValueDBE, true )
Buffer newAttrBufferValue = create
newAttrBufferValue += HB_stripRichText( newAttrStrValue )
Buffer oldAttrBufferValue = create
oldAttrBufferValue += HB_stripRichText( oldAttrStrValue )
Buffer diffResult = create
diff( diffResult, oldAttrBufferValue, newAttrBufferValue, "\\cf1\\strike ", "\\cf3\\ul " )
set( HB_oldAttrValueDBE, stringOf( diffResult ) )
delete newAttrBufferValue
delete oldAttrBufferValue
delete diffResult
}
else {
useRTFColour( HB_oldAttrValueDBE, false )
set( HB_oldAttrValueDBE, oldAttrStrValue )
}
}
else {
set( HB_oldAttrValueDBE, " " )
}
}
void HB_onListViewDeselect( DBE x, int i ) {}
void HB_onListViewActivate( DBE x, int i ) {}
void HB_populateHistoryListBox( DBE HB_historyListViewDBE, Module m, Object o, Baseline b, int &count ) {
// For baseline Modules, retrieve Object handle by Absolute Number
if ( !null b ) {
( current ModuleRef__ ) = m
showDeletedObjects( true )
o = object( intOf( o."Absolute Number" "" ) )
}
if ( !null o ) {
History h
for h in o do {
insert( HB_historyListViewDBE, -count, h.author "", iconNone )
set( HB_historyListViewDBE, -count, HB_COLUMN_SESSION, h.sessionNo "" )
set( HB_historyListViewDBE, -count, HB_COLUMN_DATE, h.date "" )
string modification = h.type ""
if ( modification == "modifyObject" ) {
modification = modification " attribute '" h.attrName "'"
put( HB_oldAttrValues, -count, removeUnlistedRichText( h.oldValue ) )
put( HB_newAttrValues, -count, removeUnlistedRichText( h.newValue ) )
}
set( HB_historyListViewDBE, -count, HB_COLUMN_MODIFICATION, modification )
string versionInfo = ""
if ( !null b ) {
versionInfo = "baseline " versionString( moduleVersion( m ) ) " - " ( dateOf b ) ""
}
else {
versionInfo = "current " version( m ) ""
}
set( HB_historyListViewDBE, -count, HB_COLUMN_BASELINE, versionInfo )
count--
}
}
}
void HB_onViewChangesAsRedliningToggle( DBE x ) {
HB_onListViewSelect( x, get( HB_historyListViewDBE ) )
}
void HB_TabSelectFn( DBE theTab ) {
int selection = get theTab
showSelectedTab( HB_TabSkip, selection )
}
void HB_doGeneralTab( DB HB_DB,
DBE HB_TabDBE,
Skip HB_GeneralTabSkip
)
{
string dummyList[] = {}
HB_historyListViewDBE = listView( HB_DB,
HB_historyListViewDBE_options,
HB_historyListViewDBE_width,
HB_historyListViewDBE_lines,
dummyList
)
set( HB_historyListViewDBE, HB_onListViewSelect, HB_onListViewDeselect, HB_onListViewActivate )
HB_oldAttrValueDBE = richText( HB_DB, HB_oldAttrValueDBE_label, "", HB_oldAttrValueDBE_width, HB_oldAttrValueDBE_height, true )
HB_newAttrValueDBE = richText( HB_DB, HB_newAttrValueDBE_label, "", HB_newAttrValueDBE_width, HB_newAttrValueDBE_height, true )
HB_viewChangesAsRedliningDBE = toggle( HB_DB, HB_viewChangesAsRedliningDBE_label, false )
set( HB_viewChangesAsRedliningDBE, HB_onViewChangesAsRedliningToggle )
HB_historyListViewDBE->"top"->"inside"->HB_TabDBE
HB_historyListViewDBE->"left"->"inside"->HB_TabDBE
int index = 0
put( HB_GeneralTabSkip, index++, HB_historyListViewDBE )
put( HB_GeneralTabSkip, index++, HB_oldAttrValueDBE )
put( HB_GeneralTabSkip, index++, HB_newAttrValueDBE )
put( HB_GeneralTabSkip, index++, HB_viewChangesAsRedliningDBE )
}
void HB_doAboutTab( DB HB_DB,
DBE HB_TabDBE,
Skip HB_AboutTabSkip
)
{
HB_aboutTextDBE = richText( HB_DB, HB_TITLE, HB_ABOUT, 1, 1, true )
HB_aboutTextDBE->"top"->"inside"->HB_TabDBE
HB_aboutTextDBE->"left"->"inside"->HB_TabDBE
HB_aboutTextDBE->"right"->"inside"->HB_TabDBE
int index = 0
put( HB_AboutTabSkip, index++, HB_aboutTextDBE )
}
bool HB_closeModuleTrigger( Trigger t ) {
hide HB_DB
return true
}
void HB_closeModule( DB x ) {
delete HB_Trigger
hide HB_DB
}
void HB_createBox( Module m, Object o ) {
HB_DB = create( "Object '" identifier( o ) "' - " HB_TITLE, styleFixed )
HB_TabSkip = create
HB_TabDBE = tab( HB_DB, HB_TAB_LABELS, HB_TAB_WIDTH, HB_TAB_HEIGHT, HB_TabSelectFn )
HB_GeneralTabSkip = create
HB_doGeneralTab( HB_DB, HB_TabDBE, HB_GeneralTabSkip )
put( HB_TabSkip, HB_GENERAL_TAB, HB_GeneralTabSkip )
HB_AboutTabSkip = create
HB_doAboutTab( HB_DB, HB_TabDBE, HB_AboutTabSkip )
put( HB_TabSkip, HB_ABOUT_TAB, HB_AboutTabSkip )
close( HB_DB, true, HB_closeModule )
HB_Trigger = trigger( module->( m."Name" "" ), close, 10, HB_closeModuleTrigger )
realize HB_DB
showSelectedTab( HB_TabSkip, HB_GENERAL_TAB )
setSize( HB_DB, HB_DB_WIDTH, HB_DB_HEIGHT )
insertColumn( HB_historyListViewDBE, HB_COLUMN_USER, HB_COLUMN_USER_LABEL, HB_COLUMN_USER_WIDTH, iconNone )
insertColumn( HB_historyListViewDBE, HB_COLUMN_SESSION, HB_COLUMN_SESSION_LABEL, HB_COLUMN_SESSION_WIDTH, iconNone )
insertColumn( HB_historyListViewDBE, HB_COLUMN_DATE, HB_COLUMN_DATE_LABEL, HB_COLUMN_DATE_WIDTH, iconNone )
insertColumn( HB_historyListViewDBE, HB_COLUMN_MODIFICATION, HB_COLUMN_MODIFICATION_LABEL, HB_COLUMN_MODIFICATION_WIDTH, iconNone )
insertColumn( HB_historyListViewDBE, HB_COLUMN_BASELINE, HB_COLUMN_BASELINE_LABEL, HB_COLUMN_BASELINE_WIDTH, iconNone )
}
void HP_populateBox( Module m, Object o ) {
// Looping through and loading baselines in the same loop sometimes causes an exception error
// in DOORS 7.0 SP1 and DOORS 7.1, so buffer the baselines in a Skip list
Skip baselines = create
int baselineCount = 0
Baseline b
for b in m do {
if ( !null b ) {
baselineCount++
put( baselines, baselineCount, b )
}
}
HB_oldAttrValues = create
HB_newAttrValues = create
// Populate History records for Baselines
int historyRecordCount = 0
Module baselineModule
for b in baselines do {
baselineModule = load( b, false )
if ( !null baselineModule ) {
HB_populateHistoryListBox( HB_historyListViewDBE, baselineModule, o, b, historyRecordCount )
}
}
delete baselines
// Populate History records for current Version of Module
( current ModuleRef__ ) = m
HB_populateHistoryListBox( HB_historyListViewDBE, m, o, null, historyRecordCount )
}
if ( !null current Module ) {
if ( !null current Object ) {
if ( !isBaseline( current Module ) ) {
HB_createBox( current Module, current Object )
HP_populateBox( current Module, current Object )
show HB_DB
}
else {
warningBox( HB_warnBaseline )
}
}
else {
warningBox( HB_warnNullObject )
}
}
else {
warningBox( HB_warnNullModule )
}
|
Re: Object History not freeing Memory I doubt it is skiplist are causing the leak. When I parse through baseline and object history I always see the memory leak not matter how careful I am about cleaning up. I've always assumed there was a memory leak in the history parsing functions but have been to lazy to figure out which part is the actual culprit. |
Re: Object History not freeing Memory There is some cleaning up to do. - Skip lists for the dialog is not deleted. - More important, the plainText buffer in function HB_stripRichText is never deleted. I would rewrite the function with the buffer as parameter instead. Then you can control the buffer by creating and deleteing it outside the function. Something like this:
void HB_stripRichText( Buffer &plainText, string rts ) {
RichText rt
for rt in rts do {
plainText += rt.text
if ( rt.newline ) plainText += "\n"
}
}
Buffer plainText = create
HB_stripRichText( plainText, rts )
// DO something
delete plainText
|